big_integer
An immutable signed integer type, supporting extremely large values (upwards of 100,000 decimal digits).
Literals of big_integer
type can be written like integers, but with the suffix L
, e.g. 123L
or 0x123L
. big_integer
s support the operators +
, -
, *
, /
and %
with typical behavior.
Since
0.12.0
Properties
Functions
Returns the absolute value of this big_integer
; i.e. the big_integer
itself if it's positive or its negation if it's negative.
Create a big_integer
from a byte array.
The byte array is interpreted with the first bit representing the sign (two's complement), and for subsequent bits, more significant bits are on the left and less significant bits are on the left (big-endian).
Inverse of big_integer.to_bytes()
.
Create a big_integer
from a byte array.
The byte array is interpreted with more significant bits on the left and less significant bits on the right (big-endian). An empty byte array is interpreted as 0
.
Inverse of big_integer.to_bytes_unsigned()
.
Parses an unsigned hexadecimal text representation of a big_integer
.
Base prefixes are not supported, so one must write e.g. integer.from_hex('CAFE')
rather than integer.from_hex('0xCAFE')
.
Case is ignored, i.e. integer.from_hex('CAFE')
and integer.from_hex('cafe')
are equivalent.
Parse a signed base-10 text representation of an integer.
Parse a signed text representation of an integer. The integer is interpreted in the specified radix (from 2 to 36 inclusive).
Returns the greater of this and another big_integer
value; i.e. value
if value
is greater than this, or this big_integer
otherwise.
Returns the numerically greater of this big_integer
a decimal
value; i.e. value
if value
is greater than this big_integer
, or this big_integer
otherwise.
Returns the lesser of this and another big_integer
value; i.e. value
if value
is less than this, or this big_integer
otherwise.
Returns the numerically lesser of this big_integer
a decimal
value; i.e. value
if value
is less than this big_integer
, or this big_integer
otherwise.
Raise this big_integer
to the power of the given exponent. SQL compatible.
Note that:
the exponent cannot be negative
if the exponent is 0, the result is 1
if the exponent is 1, the result is the original value
Convert this big_integer
to a byte array.
The first bit of the generated byte array represents the sign (two's complement), and for subsequent bits, more significant bits are on the left and less significant bits are on the left (big-endian).
Inverse of big_integer.from_bytes()
.
Examples:
0L.to_bytes()
returnsx'00'
(-1L).to_bytes()
returnsx'FF'
1L.to_bytes()
returnsx'01'
2L.pow(100).to_bytes()
returnsx'10000000000000000000000000'
Convert this non-negative big_integer
to a byte array, with no sign bit.
The generated byte array has more significant bits on the left and less significant bits on the right (big-endian).
Inverse of big_integer.from_bytes_unsigned()
.
When this big_integer
is equal to 0
, the empty byte array x''
is returned (this is consistent with the inverse function big_integer.from_bytes_unsigned()
, which interprets x''
as 0
).
Examples:
0L.to_bytes_unsigned()
returnsx''
(-1L).to_bytes_unsigned()
throws an exception1L.to_bytes_unsigned()
returnsx'01'
2L.pow(100).to_bytes_unsigned()
returnsx'10000000000000000000000000'
Convert this big_integer
to a decimal.
Convert this big_integer to an integer.
Convert this big_integer
to a base 10 text representation.
Convert this big_integer
to a text representation with the specified radix.
Does not include a base prefix in the output, i.e. integer(25).to_text(16)
returns 19
rather than 0x19
.
Supported radixes are from 2 to 36 (inclusive).